package websql;
import java.sql.ResultSet;


public class Var {
	public static String[] getVarNames(int qid) throws Exception{
		String sql="select vname from var where qid = '"+qid+"'";
		ResultSet rs=DBcon.getConn().createStatement().executeQuery(sql);
		rs.last();
		String vname[]=new String[rs.getRow()];
		rs.beforeFirst();
		while(rs.next()){
			String tmp=rs.getString("vname");
				tmp=unit.EscapeUnescape.unescape(tmp);
			vname[rs.getRow()-1]=tmp;
		}
		return vname;
	}
	public static int getvid(String what,String iswhat) throws Exception{
		String sql="select vid from var where "+what+" = '"+iswhat+"'";
		ResultSet rs=DBcon.getConn().createStatement().executeQuery(sql);
		rs.next();
		int qid=rs.getInt("vid");
		return qid;
	}

	public static String get(String what,int whichvid) throws Exception{
		String sql="select "+what+" from var where vid = '"+whichvid+"'";
		ResultSet rs=DBcon.getConn().createStatement().executeQuery(sql);
		rs.next();
		String answer=rs.getString(what);
		return answer;
	}

}
